package com.baizhi.wd.view;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baizhi.wd.entity.Person;

public class QueryAllView extends HttpServlet {
	public void service(HttpServletRequest request,HttpServletResponse response) throws IOException{
		// 1 设置响应类型
		response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		
        // 2 获取输出流
		PrintWriter out = response.getWriter();

		Object obj = request.getAttribute("List");
		List<Person> list = (List<Person>)obj;

		
        // 3 使用输出流
		out.println("<html>");
		out.println("<head><title>通讯录项目</title></head>");
		out.println("<body>");
		
		out.println("<a href='/telbook_2/LoginView.html'>退出</a></br>");
		out.println("<a href='/telbook_2/addPerson.html'>添加数据</a></br>");
		out.println("<table width='80%' border='1' cellspacing='0' cellpadding='0'>");
	    out.println("<tr>");
	    out.println("<th>姓名</th>");
	    out.println("<th>手机</th>");    
	    out.println("<th>座机</th>");    
	    out.println("<th>邮箱</th>");     
	    out.println("<th>城市</th>");
	    out.println("<th>生日</th>");
	    out.println("<th>操作</th>");
	    out.println("</tr>");
		// 从request中取数据
		if (list.size() == 0){
			out.println("<tr><td colspan='7' align='center'>暂无数据！</td></tr>");
		} else {
			for (Person per : list) {
				out.println("<tr>");
				out.println("<td><a href='/telbook_2/per/queryPersonDetailAction?id="+per.getId()+"'>"+per.getName()+"</a></td>");
				out.println("<td>"+per.getMobile()+"</td>");
				out.println("<td>"+per.getTelphone()+"</td>");
				out.println("<td>"+per.getEmail()+"</td>");
				out.println("<td>"+per.getCity()+"</td>");
				out.println("<td>"+per.getBirthday()+"</td>");
				out.println("<td><a href='/telbook_2/per/updateQueryOneAction?id="+per.getId()+"'>修改</a> <a href='/telbook_2/per/deletePersonAction?id="+per.getId()+"'>删除</a></td>");
				
				out.println("</tr>");
			
			}
		}
		out.println("</body>");
		out.println("</html>");
	}
}
